package com.xiaoshuidi.cloud.module.rooms.repository;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomHouseFilingsMapper;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomHouseFilings;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author hans.zhang
 */
@Component
@RequiredArgsConstructor
public class RoomHouseFilingsRepository extends ServiceImpl<RoomHouseFilingsMapper, RoomHouseFilings> {
    public RoomHouseFilings getByRoomHouseId(Long roomHouseId) {
        LambdaQueryWrapper<RoomHouseFilings> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RoomHouseFilings::getRoomHouseId, roomHouseId);
        wrapper.orderByDesc(RoomHouseFilings::getCreateTime);
        List<RoomHouseFilings> filings = list(wrapper);
        if (ObjectUtil.isNotEmpty(filings)) {
            return filings.get(0);
        } else {
            return null;
        }
    }
}
